/*jslint vars:true plusplus:true devel:true*/

//=========================================================
// Interactive Digital Media Diploma
// CUFDIG404A_R1: Introduction to Scripting
// Assignment 3
// Author: Ben
// File: buggy.js
// Description: Buggy functionality
//=========================================================

function BuggyBullet(sprite, x, y) {
    "use strict";
    var self = this;
    var startX = 300;

    var entity = new Entity(sprite, x, y);
    
    // the bullet has been hit
    this.onHit = function (collider, collisionLayer, other) {
        // on hit functionality here
        if (collisionLayer === game.environmentLayer){
            self.setEnabled(false);
        }
    };

    this.setEnabled = function(enabled){
        entity.isVisible = enabled;
        collider.isEnabled = enabled;
    };
    
    this.isEnabled = function(){
        return entity.isVisible;
    };
    
    var collider = new Collider(entity, 10,window.game.buggyLayer, 0, 0, self.onHit);
    
    var x_velocity = 400;
    
    // update the Bullet every frame
    this.update = function () {
        entity.x += x_velocity / window.game.frameRate;

        if (entity.x > 400 + startX){
            self.setEnabled(false);
        }
        entity.incSprite();
    };
    
  //
    this.start = function ( x,y) {
        startX = x;
        entity.x = x;
        entity.y = y;
    };
}
